


const Cu = Components.utils;
function require(url) {
    let scope = {};
    Cu.import(url, scope);
    return scope;
}
let {Prefs} = require("chrome://jsm/content/Preferences.js");

window.onload = function () {
    let group = document.getElementById("record-mode-group");
    let val = Prefs.recordingMode;
    if (!/^(:?auto|conventional|events|xy)$/.test(val)) {
        val = "auto";
        Prefs.recordingMode = "auto";
    }
    let item = document.getElementById(val);
    group.selectedItem = item;

    let expert_box = document.getElementById("expert-mode");
    expert_box.checked = Prefs.useExpertMode;

    let id_priority = document.getElementById("id-priority");
    id_priority.checked = Prefs.preferIds;

    if (val == "conventional") {
        expert_box.disabled = false;
        id_priority.disabled = expert_box.checked;
    }

    group.addEventListener("command", function(e) {
        if (e.target.id == "conventional") {
            expert_box.disabled = false;
            id_priority.disabled = expert_box.checked;
        } else if (/xy|auto|events/.test(e.target.id)) {
            expert_box.disabled = true;
            id_priority.disabled = false;
        }
    });

    
    

    expert_box.addEventListener("command", function(e) {
        id_priority.disabled = expert_box.checked;
    });
};


function do_accept () {         
    let group = document.getElementById("record-mode-group");
    let id = group.selectedItem.id;
    let id_priority = document.getElementById("id-priority");
    Prefs.recordingMode = id;
    Prefs.preferIds = id_priority.checked;
    var expert_box = document.getElementById("expert-mode");
    Prefs.useExpertMode = expert_box.checked;
    window.close();
}
